package com.school.controller;

import com.school.entity.Orders;
import com.school.entity.Tickets;
import com.school.service.OrdersService;
import com.school.service.TicketsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/Tickets")
public class TicketsController {
    @Autowired
    TicketsService service;
    @Autowired
    OrdersService ordersService;

    // HttpServletRequest request, HttpServletResponse response

    @ResponseBody
    @RequestMapping("/getAll.do")
    public Tickets getAll(String ticket_id) {
        Tickets tickets = service.selectAll(ticket_id);
        return tickets;
    }

    @ResponseBody
    @RequestMapping("/insertOne.do")
    public int insertInfo(String user_phone, String ticket_id, String ticket_name, String ticket_date, String ticket_number) {
        Tickets tickets = new Tickets(ticket_id, ticket_name, ticket_date, ticket_number);
        int i = service.insertOne(tickets);
        System.out.println("ticket插入 = " + i);
        if (i > 0) {
            Orders orders = new Orders(user_phone, ticket_id);
            int i2 = ordersService.insertOne(orders);
            System.out.println("order插入 = " + i2);
        }
        return i;
    }

    @ResponseBody
    @RequestMapping("/updateOne.do")
    public int updateOne(String ticket_id, String ticket_name, String ticket_date, String ticket_number) {
        Tickets tickets = new Tickets(ticket_id, ticket_name, ticket_date, ticket_number);
        int i = service.updateOne(tickets);
        System.out.println("更新 = " + i);
        return i;
    }

    @ResponseBody
    @RequestMapping("/deleteOne.do")
    public int updateOne(String ticket_id) {
        System.out.println("ticket_id=" + ticket_id);
        int i = service.deleteOne(ticket_id);
        System.out.println("删除 = " + i);
        return i;
    }


}
